{extend name='./content'}

{block name="button"}
<div class="nowrap pull-right" style="margin-top:10px">
    <div class="layui-btn-group shop_name">
        统计金额<span>  {$sum_money} </span>人 交易笔数<span>  {$sum_order} </span>人

        <a href="{$self_url}&#38;date_type="
           class="layui-btn layui-btn-small {if $Think.get.date_type != ''}layui-btn-primary{else/}layui-btn-normal{/if}">全部</a>
        <a href="{$self_url}&#38;date_type=month"
           class="layui-btn layui-btn-small {if $Think.get.date_type != 'month'}layui-btn-primary{else/}layui-btn-normal{/if}">本月</a>
        <a href="{$self_url}&#38;date_type=week"
           class="layui-btn layui-btn-small {if $Think.get.date_type != 'week'}layui-btn-primary{else/}layui-btn-normal{/if}">本周</a>
        <a href="{$self_url}&#38;date_type=day"
           class="layui-btn layui-btn-small {if $Think.get.date_type != 'day'}layui-btn-primary{else/}layui-btn-normal{/if}">今日</a>
    </div>
    <a href="{$self_no_url}&action=dump" target="_blank" class="layui-btn layui-btn-small" style="">导出数据</a>
    <button type="button" class="layui-btn layui-btn-small layui-btn-danger" data-modal="/manage/order/del_batch">
        <i class="fa fa-remove"></i> 删除无效订单
    </button>
</div>
{/block}

{block name="content"}

<!-- 表单搜索 开始 -->
<form class="layui-form form-search" action="__SELF__" onsubmit="return false" method="get">
    <div class="layui-form-item layui-inline">
        <label class="layui-form-label">商户账号</label>
        <div class="layui-input-inline">
            <input name="username" value="{$Think.get.username|default=''}" placeholder="请输入商户账号" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-inline">
        <label class="layui-form-label">联系方式</label>
        <div class="layui-input-inline">
            <input name="contact" value="{$Think.get.contact|default=''}" placeholder="请输入客户联系方式" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-inline">
        <label class="layui-form-label">订单号</label>
        <div class="layui-input-inline">
            <input name="trade_no" value="{$Think.get.trade_no|default=''}" placeholder="请输入支付订单号" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-inline">
        <label class="layui-form-label">卡密信息</label>
        <div class="layui-input-inline">
            <input name="card" value="{$Think.get.card|default=''}" placeholder="请输入卡密信息" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-inline">
        <label class="layui-form-label">支付渠道</label>
        <div class="layui-input-inline">
            <select name="channel_id">
                <option value="">全部渠道</option>
                {foreach $channels as $v}
                <option value="{$v.id}" {if $Think.get.channel_id== $v.id}selected{
                /if}>{$v.title}</option>
                {/foreach}
            </select>
        </div>
    </div>
    <div class="layui-form-item layui-inline">
        <label class="layui-form-label">支付方式</label>
        <div class="layui-input-inline">
            <select name="paytype">
                <option value="">请选择</option>
                {foreach $channel_paytype as $k => $v}
                <option value="{$v.id}" {if intval($Think.get.paytype)===intval($v.id)}selected{/if}>{$v.name}</option>
                {/foreach}
            </select>
        </div>
    </div>
    <div class="layui-form-item layui-inline">
        <label class="layui-form-label">订单状态</label>
        <div class="layui-input-inline">
            <select name="status">
                <option value="">请选择</option>
                <option value="1" {if $Think.get.status===
                '1'}selected{/if}>已成功</option>
                <option value="0" {if $Think.get.status===
                '0'}selected{/if}>未支付</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item layui-inline">
        <label class="layui-form-label">冻结状态</label>
        <div class="layui-input-inline">
            <select name="is_freeze">
                <option value="">全部状态</option>
                <option value="1" {if $Think.get.is_freeze===
                '1'}selected{/if}>已冻结</option>
                <option value="0" {if $Think.get.is_freeze===
                '0'}selected{/if}>未冻结</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item layui-inline">
        <label class="layui-form-label">时间范围</label>
        <div class="layui-input-inline">
            <input name="date_range" id="date_range" value="{:urldecode($Think.get.date_range)}" placeholder="请选择时间范围"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-inline">
        <label class="layui-form-label">展现方式</label>
        <div class="layui-input-inline">
            <select name="show">
                <option value="sheet" {if $Think.get.show==='' || $Think.get.show === 'sheet'}selected{/if}>表格</option>
                <option value="chart" {if $Think.get.show==='chart'}selected{/if}>图表</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item layui-inline">
        <button type="submit" class="layui-btn layui-btn-primary layui-btn-small"><i class="layui-icon">&#xe615;</i> 搜 索</button>
    </div>
</form>
<!-- 表单搜索 结束 -->

{if $Think.get.show=='chart'}
<div id="statis_chart" style="width: 100%;height:300px;"></div>
<script>
    var statis_chart = echarts.init(document.getElementById('statis_chart'));
    var month_option = {
        title: {
            text: '交易统计'
        },
        color: ['#45c8f4', '#4ab47a'],
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'cross'
            }
        },
        legend: {
            data: ['交易金额', '收入金额']
        },
        grid: {
            top: 70,
            bottom: 50
        },
        xAxis: [
            {
                type: 'category',
                boundaryGap: false,
                data: [{$statis_chart.title
            }]
    }
    ],
    yAxis: [
        {
            type: 'value'
        }
    ],
        series
    :
    [
        {
            name: '交易金额',
            type: 'line',
            smooth: true,
            data: [{$statis_chart.transaction_money
        }]
    },
    {
        name:'收入金额',
            type
    :
        'line',
            smooth
    :
        true,
            data
    :
        [{$statis_chart.actual_money
    }]
    }
    ]
    }
    ;

    statis_chart.setOption(month_option);
</script>
{else/}
<form onsubmit="return false;" data-auto="true" method="post">
    <input type="hidden" value="resort" name="action"/>
    <table class="table table-hover">
        <thead>
        <tr>
            <th class='text-center'>订单编号</th>
            <th class='text-center'>商品名称</th>
            <th class='text-center'>卖家</th>
            <th class='text-center'>买家</th>
            <th class='text-center'>交易金额</th>
            <!--th class='text-center'>手续费</th-->
            <th class='text-center'>当前状态</th>
            <!--th class='text-center'>冻结状态</th-->
            <th class='text-center'>交易时间</th>
            <th class='text-center'>操作</th>
        </tr>
        </thead>
        <tbody>
        <!--{php} $money1 = 0; {/php}-->
        {foreach $orders as $v}
        <!--{php} $money1 += $v['money1'];{/php}-->
        <tr>
			<td class='text-center'>{$v.ddbh}</td>
			<td class='text-center' style="max-width: 200px;">[{:typename($v.type)}]{$v.tit}</td>  
            <td class='text-center' style="max-width: 100px;">
				<a data-title="卖家信息" data-open='{:url("admin/member/info")}?bh={$v.sell}' href="javascript:void(0)">{:uc_info($v.sell,'sell','name')}</a>
			</td>
            <td class='text-center' style="max-width: 100px;">
				<a data-title="买家信息" data-open='{:url("admin/member/info")}?bh={$v.buy}' href="javascript:void(0)">{:uc_info($v.buy,'buy','name')}</a>
			</td>
            <!--<td class='text-center'>{v.transaction_id}</td>-->     
            <td class='text-center'>{$v.money1}</td>
            <!--td class='text-center'>{v.fee}</td-->
            <td class='text-center'>
                {if $v.ddzt=='success'}
                <font color="green">交易完成</font>			
				{elseif $v.ddzt=='backsuc'}
                <font color="red">退款完成</font>
				{else/}
                <font color="red">正在交易</font>
                {/if}				
            </td>
            <!--td class='text-center'>
                {if 1==1}
                <a style="color:red" data-tips="确定取消冻结吗？ " data-update="{$v.id}" data-field='status' data-value='0'
                   data-action='{:url("change_freeze_status")}'
                   href="javascript:void(0)">已冻结</a>
                {else/}
                <a style="color:green" data-tips="确定冻结吗？" data-update="{$v.id}" data-field='status' data-value='1'
                   data-action='{:url("change_freeze_status")}'
                   href="javascript:void(0)">未冻结</a>
                {/if}
            </td-->
            <td class='text-center'>{$v.sj}</td>
            <td>
                <a data-title="订单详情" data-open='{:url("admin/order/detail")}?bh={$v.ddbh}' href="javascript:void(0)">详情</a>
				{if 1==1}
                <a href="javascript:;" onclick="order_del(this,'{$v.id}')">删除</a>
                {/if}
            </td>
        </tr>
        {/foreach}
        </tbody>
    </table>
</form>
{$page}
<ul style="display: inline-block;padding-left: 0;margin: 20px 0;border-radius: 4px;">
    <li style="position: relative; float: left; padding: 6px 12px; margin-left: 10px; line-height: 1.42857143; text-decoration: none; background-color: #fff;">
        该页成功金额 {$money1} 元
    </li>
</ul>
{/if}
<script>
    layui.use('form', function () {
        var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
        form.render();
    });
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        //日期范围
        laydate.render({
            elem: '#date_range',
            range: true
        });
    });

    /*订单-删除*/
    function order_del(obj, id) {
        layer.confirm('确认要删除这个订单吗？该操作不可恢复', function (index) {
            $.ajax({
                url: "/manage/order/del",
                type: 'post',
                data: 'id=' + id,
                success: function (res) {
                    if (res.code == 1) {
                        $(obj).parents("tr").remove();
                        layer.msg('已删除!', {icon: 1, time: 1000});
                    } else {
                        layer.msg('删除失败!', {icon: 1, time: 1000});
                    }
                }
            });
        });
    }
</script>
{/block}
